<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2019/12/28 0028
// +----------------------------------------------------------------------
// | Description:  
// +----------------------------------------------------------------------

namespace app\admin\controller;
use QL\QueryList as Qlist;

class Querylists extends AdminBase
{

    protected  $qlist;
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->qlist=Qlist::getInstance(); //实例化querylist
    }


    /**
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2019/12/28 0028
     * @name: index
     * @describe： 采集信息
     */
    public function index(){
       $all= $this->qlist->get("www.baidu.com",'img','attr');
       dump($all);
    }


    /**
     * @param $zhongwen
     * @return mixed|string
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2019/12/28 0028
     * @name: cnki_transt
     * @describe：cnki 翻译医学字符
     */
    public function cnki_transt($zhongwen){
        //$zhongwen='胃癌';
        $url  = "http://dict.cnki.net/dict_result.aspx?searchword=".urlencode(
                $zhongwen
            )."&style=&tjType=translate_search";
        $rule = [
            'html' => ['#lblresult .zztj font', 'html'],
        ];
        $data=Qlist::getInstance()->get($url, $rule)->getData();

        $val  = '';
        if (empty($data)) { //调取百度翻译

        } else {  //调取cnki翻译
            foreach ($data as $k => $v) {
                $v['html'] = strip_tags($v['html']);
                $arr       = explode('(', $v['html']);
                if ($this->is_han($arr[0])) {
                    continue;
                }
                $val = $arr[0];
                break;
            }
        }
       // dump($val);
        return $val;
    }




    /**
     * @param $str
     * @return bool
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2019/12/28 0028
     * @name: is_han
     * @describe：判断是否是汉字
     */
    private function is_han($str)
    {
        if (preg_match("/([\x81-\xfe][\x40-\xfe])/", $str, $match)) {
            return true;
        } else {
            return false;
        }
    }




}